package reflect;

import java.lang.reflect.Method;

/**
 * 调用有参方法
 */
public class ReflectDemo5 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance(); //实例化
        //say(String info)
        Method m1 = cls.getMethod("say",String.class);  //方法名,参数列表
        m1.invoke(obj,"你好");//obj.say("你好");  所属对象,实参

        //say(String info,int count)
        Method m2 = cls.getMethod("say",String.class,int.class);
        m2.invoke(obj,"呵呵",5);
    }
}
